import torch
import numpy as np

np_data=np.arange(6).reshape((2,3))
torch_data=torch.from_numpy(np_data)    #numpy 转 tensor
tensor2array=torch_data.numpy()         #tensor 转 numpy
print(
    '\nnumpy',np_data,
    '\ntorch',torch_data,
    '\ntensor2array',tensor2array,
)

#一些基本的运算
data=[1,2,3,4]
tensor = torch.FloatTensor(data)
print('\nsin',torch.sin(tensor))

#矩阵相乘
data=[[1,2],[3,4]]
tensor = torch.FloatTensor(data)
print('\nsin',torch.mm(tensor,tensor))